The simplest case of a regression is the regression line. This means that the assumed relationship between the input and output signal is a linear straight line.
Figure: Regression line
LGF_RegressionLine (FC) | ||||||||
---|---|---|---|---|---|---|---|---|
Ret_Val | Void | |||||||
slope | LReal | |||||||
intercept | LReal | |||||||
error | Bool | |||||||
status | Word | |||||||
Array[*] of LGF_typeRegressionLine | values | Array[*] of LGF_typeRegressionLine | ||||||
Identifier | Data type | Description |
---|---|---|
Ret_Val | Void | Void - Function has no return value |
slope | LReal | Gradient of straight line |
intercept | LReal | The intersection with the Y axis |
error | Bool | FALSE: No error TRUE: An error occurred during the execution of the FB |
status | Word | 16#0000-16#7FFF: Status of the FB 16#8000-16#FFFF: Error identification (see following Table) |
Identifier | Data type | Description |
---|---|---|
values | Array[*] of LGF_typeRegressionLine | The data points are transferred with their X- and Y-values. The data type `LGF_typeRegressionLine` has the following structure: • x (Real) • y (Real) |
Code / Value | Identifier / Description |
---|---|
16#0000 | STATUS_EXECUTION_FINISHED Status: Execution finished without errors |
16#8200 | ERR_NOT_ENOUGH_VALUES Error: Not enough Values. The block requires at least two pairs of values to calculate a regression line. Increase the size of the array at the input parameter `values` in the second dimension. |
The data type is for transferring datapoints (Key- Value pairs) to LGF_RegressionLine
and calculate the interpolated linear equation parameters slope and intercept.
Identifier | Data type | Default value | Description |
---|---|---|---|
x | Real | 0.0 | X-Axis value |
y | Real | 0.0 | Y-Axis value |
The block calculates the regression line with the following line equation:
f(x) = m \cdot x + t
m: Gradient of straight line
t: Intersection with y-axis
N: number of array elements
The gradient m is calculated using the following equation:
m = \frac{n \cdot \sum_{1}^{N}(x(n) \cdot y(n)) - (\sum_{1}^{N}x(n) \cdot \sum_{1}^{N}y(n))}{n \cdot \sum_{1}^{N} x^2(n) - (\sum_{1}^{N}x(n))^2}The intersection t with the Y axis is calculated using the following equation:
t = \frac{\sum_{1}^{N} y(n)}{N} - b \cdot \frac{\sum_{1}^{N} x(n)}{N}Version & Date | Change description | |
---|---|---|
01.00.00 | Siemens Industry Online Support | |
23.11.2018 | First released version | |
01.00.04 | Simatic Systems Support | |
15.11.2019 | Code refactoring, comments added | |
03.00.00 | Simatic Systems Support | |
23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library | |
03.00.01 | Simatic Systems Support | |
06.04.2021 | Insert documentation |